package com.example.demo.admin.test.queue;/**
 * Created by kete on 2018-09-25.
 */

import java.io.File;
import java.util.concurrent.BlockingQueue;

/**
 * 作者：kete
 * 创建时间：2018-09-25 16:07
 * 功能描述：
 * 版本：
 */
public class ProducerFile implements Runnable {

    private final BlockingQueue<File> queue;

    private final  File root;

    public ProducerFile(BlockingQueue<File> queue,File root) {
        this.root = root;
        this.queue = queue;
    }

    @Override
    public void run() {

        try {
            crawl(root);
        } catch (InterruptedException e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
        }
    }


    private void crawl(File root) throws InterruptedException{
        File[] list = root.listFiles();
        if(list!=null){
            for(File file : list){
                if(file.isDirectory()){
                    crawl(file);

                }else{
                    queue.put(file);
                }
            }
        }

    }
}
